package cn.sumpu.app.guoguojie.domain;

import java.io.Serializable;
import java.util.*;

public class DoingTag implements Serializable {

	private static final long serialVersionUID = 6719077864563506939L;
	public DoingTag(){}
	public DoingTag(String identifier, String name){
		this.identifier = identifier;
		this.name = name;
	}
	//所有标签
	public static List<DoingTag> doingTagAll = new ArrayList<DoingTag>();
	//所有标签的名称
	public static List<DoingTag> doingTagName = new ArrayList<DoingTag>();

	private String identifier;
	private String parentIdentifier;
	private String name;
	private Integer deep;
	private Boolean enabled = true;
	private Date gmtCreated;
	private Date gmtModified;
	private Integer type;
	//自己的子类
	private List<DoingTag> tagList = new ArrayList<DoingTag>();
	//自己的父类
	private DoingTag doingTag;
	//标签的权重
	private Integer weight;
	
	
	public Integer getWeight() {
		return weight;
	}
	public void setWeight(Integer weight) {
		this.weight = weight;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	public DoingTag getDoingTag() {
		return doingTag;
	}
	public void setDoingTag(DoingTag doingTag) {
		this.doingTag = doingTag;
	}
	public List<DoingTag> getTagList() {
		return tagList;
	}
	public void setTagList(List<DoingTag> tagList) {
		this.tagList = tagList;
	}
	public Integer getDeep() {
		return deep;
	}
	public void setDeep(Integer deep) {
		this.deep = deep;
	}
	public Boolean getEnabled() {
		return enabled;
	}
	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}
	public String getIdentifier() {
		return identifier;
	}
	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}
	public String getParentIdentifier() {
		return parentIdentifier;
	}
	public void setParentIdentifier(String parentIdentifier) {
		this.parentIdentifier = parentIdentifier;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Date getGmtCreated() {
		return gmtCreated;
	}
	public void setGmtCreated(Date gmtCreated) {
		this.gmtCreated = gmtCreated;
	}
	public Date getGmtModified() {
		return gmtModified;
	}
	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof DoingTag && this.identifier.equals(((DoingTag)obj).getIdentifier())){
			return true;
		}else{
			return false;
		}
	}
	//根据父ID取得子标签集合(遍历树)
	public static List<DoingTag> getTagsByPid(String parentId){
		if(parentId.equals("0")){
			return doingTagAll;
		}
		for(DoingTag t : doingTagAll){
			if(t.getIdentifier().equals(parentId)){
				return t.getTagList();
			}
			List<DoingTag> list = getTagsByPid(t.getTagList(), parentId);
			if(list.size()>0){
				return list;
			}
		}
		return new ArrayList<DoingTag>();
	}
	public static List<DoingTag> getTagsByPid(List<DoingTag> l, String parentId){
		for(DoingTag t : l){
			if(t.getIdentifier().equals(parentId)){
				return t.getTagList();
			}
			List<DoingTag> list = getTagsByPid(t.getTagList(), parentId);
			if(list!=null && list.size()>0){
				return list;
			}
		}
		return new ArrayList<DoingTag>();
	}
	
}
